// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using Elastic.Transport;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.Security
{
	public sealed class SecurityHasPrivilegesRequestParameters : RequestParameters<SecurityHasPrivilegesRequestParameters>
	{
	}

	public sealed partial class SecurityHasPrivilegesRequest : PlainRequestBase<SecurityHasPrivilegesRequestParameters>
	{
		public SecurityHasPrivilegesRequest()
		{
		}

		public SecurityHasPrivilegesRequest(Elastic.Clients.Elasticsearch.Name? user) : base(r => r.Optional("user", user))
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.SecurityHasPrivileges;
		protected override HttpMethod HttpMethod => HttpMethod.POST;
		protected override bool SupportsBody => true;
		[JsonInclude]
		[JsonPropertyName("application")]
		public IEnumerable<Elastic.Clients.Elasticsearch.Security.ApplicationPrivilegesCheck>? Application { get; set; }

		[JsonInclude]
		[JsonPropertyName("cluster")]
		public IEnumerable<Elastic.Clients.Elasticsearch.Security.ClusterPrivilege>? Cluster { get; set; }

		[JsonInclude]
		[JsonPropertyName("index")]
		public IEnumerable<Elastic.Clients.Elasticsearch.Security.IndexPrivilegesCheck>? Index { get; set; }
	}

	public sealed partial class SecurityHasPrivilegesRequestDescriptor : RequestDescriptorBase<SecurityHasPrivilegesRequestDescriptor, SecurityHasPrivilegesRequestParameters>
	{
		internal SecurityHasPrivilegesRequestDescriptor(Action<SecurityHasPrivilegesRequestDescriptor> configure) => configure.Invoke(this);
		public SecurityHasPrivilegesRequestDescriptor()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.SecurityHasPrivileges;
		protected override HttpMethod HttpMethod => HttpMethod.POST;
		protected override bool SupportsBody => true;
		public SecurityHasPrivilegesRequestDescriptor User(Elastic.Clients.Elasticsearch.Name? user)
		{
			RouteValues.Optional("user", user);
			return Self;
		}

		private IEnumerable<Elastic.Clients.Elasticsearch.Security.ApplicationPrivilegesCheck>? ApplicationValue { get; set; }

		private ApplicationPrivilegesCheckDescriptor ApplicationDescriptor { get; set; }

		private Action<ApplicationPrivilegesCheckDescriptor> ApplicationDescriptorAction { get; set; }

		private Action<ApplicationPrivilegesCheckDescriptor>[] ApplicationDescriptorActions { get; set; }

		private IEnumerable<Elastic.Clients.Elasticsearch.Security.ClusterPrivilege>? ClusterValue { get; set; }

		private IEnumerable<Elastic.Clients.Elasticsearch.Security.IndexPrivilegesCheck>? IndexValue { get; set; }

		private IndexPrivilegesCheckDescriptor IndexDescriptor { get; set; }

		private Action<IndexPrivilegesCheckDescriptor> IndexDescriptorAction { get; set; }

		private Action<IndexPrivilegesCheckDescriptor>[] IndexDescriptorActions { get; set; }

		public SecurityHasPrivilegesRequestDescriptor Application(IEnumerable<Elastic.Clients.Elasticsearch.Security.ApplicationPrivilegesCheck>? application)
		{
			ApplicationDescriptor = null;
			ApplicationDescriptorAction = null;
			ApplicationDescriptorActions = null;
			ApplicationValue = application;
			return Self;
		}

		public SecurityHasPrivilegesRequestDescriptor Application(ApplicationPrivilegesCheckDescriptor descriptor)
		{
			ApplicationValue = null;
			ApplicationDescriptorAction = null;
			ApplicationDescriptorActions = null;
			ApplicationDescriptor = descriptor;
			return Self;
		}

		public SecurityHasPrivilegesRequestDescriptor Application(Action<ApplicationPrivilegesCheckDescriptor> configure)
		{
			ApplicationValue = null;
			ApplicationDescriptor = null;
			ApplicationDescriptorActions = null;
			ApplicationDescriptorAction = configure;
			return Self;
		}

		public SecurityHasPrivilegesRequestDescriptor Application(params Action<ApplicationPrivilegesCheckDescriptor>[] configure)
		{
			ApplicationValue = null;
			ApplicationDescriptor = null;
			ApplicationDescriptorAction = null;
			ApplicationDescriptorActions = configure;
			return Self;
		}

		public SecurityHasPrivilegesRequestDescriptor Cluster(IEnumerable<Elastic.Clients.Elasticsearch.Security.ClusterPrivilege>? cluster)
		{
			ClusterValue = cluster;
			return Self;
		}

		public SecurityHasPrivilegesRequestDescriptor Index(IEnumerable<Elastic.Clients.Elasticsearch.Security.IndexPrivilegesCheck>? index)
		{
			IndexDescriptor = null;
			IndexDescriptorAction = null;
			IndexDescriptorActions = null;
			IndexValue = index;
			return Self;
		}

		public SecurityHasPrivilegesRequestDescriptor Index(IndexPrivilegesCheckDescriptor descriptor)
		{
			IndexValue = null;
			IndexDescriptorAction = null;
			IndexDescriptorActions = null;
			IndexDescriptor = descriptor;
			return Self;
		}

		public SecurityHasPrivilegesRequestDescriptor Index(Action<IndexPrivilegesCheckDescriptor> configure)
		{
			IndexValue = null;
			IndexDescriptor = null;
			IndexDescriptorActions = null;
			IndexDescriptorAction = configure;
			return Self;
		}

		public SecurityHasPrivilegesRequestDescriptor Index(params Action<IndexPrivilegesCheckDescriptor>[] configure)
		{
			IndexValue = null;
			IndexDescriptor = null;
			IndexDescriptorAction = null;
			IndexDescriptorActions = configure;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (ApplicationDescriptor is not null)
			{
				writer.WritePropertyName("application");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, ApplicationDescriptor, options);
				writer.WriteEndArray();
			}
			else if (ApplicationDescriptorAction is not null)
			{
				writer.WritePropertyName("application");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, new ApplicationPrivilegesCheckDescriptor(ApplicationDescriptorAction), options);
				writer.WriteEndArray();
			}
			else if (ApplicationDescriptorActions is not null)
			{
				writer.WritePropertyName("application");
				writer.WriteStartArray();
				foreach (var action in ApplicationDescriptorActions)
				{
					JsonSerializer.Serialize(writer, new ApplicationPrivilegesCheckDescriptor(action), options);
				}

				writer.WriteEndArray();
			}
			else if (ApplicationValue is not null)
			{
				writer.WritePropertyName("application");
				JsonSerializer.Serialize(writer, ApplicationValue, options);
			}

			if (ClusterValue is not null)
			{
				writer.WritePropertyName("cluster");
				JsonSerializer.Serialize(writer, ClusterValue, options);
			}

			if (IndexDescriptor is not null)
			{
				writer.WritePropertyName("index");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, IndexDescriptor, options);
				writer.WriteEndArray();
			}
			else if (IndexDescriptorAction is not null)
			{
				writer.WritePropertyName("index");
				writer.WriteStartArray();
				JsonSerializer.Serialize(writer, new IndexPrivilegesCheckDescriptor(IndexDescriptorAction), options);
				writer.WriteEndArray();
			}
			else if (IndexDescriptorActions is not null)
			{
				writer.WritePropertyName("index");
				writer.WriteStartArray();
				foreach (var action in IndexDescriptorActions)
				{
					JsonSerializer.Serialize(writer, new IndexPrivilegesCheckDescriptor(action), options);
				}

				writer.WriteEndArray();
			}
			else if (IndexValue is not null)
			{
				writer.WritePropertyName("index");
				JsonSerializer.Serialize(writer, IndexValue, options);
			}

			writer.WriteEndObject();
		}
	}
}